// JavaScript Document
/*
The variable "menushimUrl" is pointed (via root relative link) at a blank page on the server
in order to supress the following Security Alert Message:

	This page contains both secure and nonsecure items.

	Do you want to display the nonsecure items?
	
*/
var menushimUrl = "scripts/blank.htm"; //Root relative url of a blank page on the server.

var numberOfMenuLevels = 2;

var keyboardFocus = null;



/*
makeFrame Function inserts 1 iframe per number of dropdowns in menu system.
The number of dropdown levels is specified in the var numberOfMenuLevels (above).
*/
makeFrame = function() {
	for (var i=0; i<numberOfMenuLevels; i++) {
		ifrm = document.createElement("IFRAME");
		ifrm.setAttribute('id', 'menushim' + i);
		ifrm.setAttribute('class', 'menushim');
		ifrm.setAttribute('src', menushimUrl);
		ifrm.setAttribute('scrolling', 'no');
		ifrm.setAttribute('frameborder', '0');
		document.body.appendChild(ifrm);
		ifrm2 = document.getElementById('menushim' + i);
		ifrm2.className = 'menushim';
	}
}
/*
sfHover Function applies ONMOUSEOVER and ONMOUSEOUT states to each LI (if it has subordinate levels) in the UL (id="nav)".
*/
sfHover = function() {
	if (document.getElementById('nav') == null) return;
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		/* Mark Expandable Menu Items */
		sfMarkContainer = sfEls[i].getElementsByTagName("LI");
		if(sfMarkContainer.length > 0) {
			sfEls[i].className = "sfexpandable";
		}
		
		/* Mouseover */
		sfEls[i].onmouseover=function() {
			this.className+=(this.className.length>0? " ": "") + "sfhover";
			tmpobj = this.getElementsByTagName('ul');
			if(tmpobj[0] != undefined){
				tmpobj2 = tmpobj[0].getElementsByTagName('a');
				tmpobj2alt = tmpobj[0].getElementsByTagName('span');
				if(this.parentNode.id == "nav"){ //When LI tag (in 1st Level) is moused over, place iframe behind exposed 2nd Level
					mnushm = document.getElementById('menushim0');
					mnushm.style.left = tmpobj[0].offsetLeft;
					mnushm.style.top = tmpobj[0].offsetTop;
					if(!tmpobj2[0]) {
						mnushm.style.width = tmpobj2alt[0].offsetWidth;
					} else {
						mnushm.style.width = tmpobj2[0].offsetWidth;
					}
					mnushm.style.height = tmpobj[0].offsetHeight;
					tmpobj[0].style.zIndex="101";
					mnushm.style.zIndex="0";
					mnushm.style.display="block";
				} else if(this.parentNode.parentNode.parentNode.id == "nav") { //When LI tag (in 2st Level) is moused over, place iframe behind exposed 3rd Level
					mnushm2ndLevel = document.getElementById('menushim1');
					if(!tmpobj2[0]) {
						mnushm2ndLevel.style.width = tmpobj2alt[0].offsetWidth;
					} else {
						mnushm2ndLevel.style.width = tmpobj2[0].offsetWidth;
					}
					mnushm2ndLevel.style.height = tmpobj[0].offsetHeight;
					mnushm2ndLevel.style.left = tmpobj[0].offsetLeft + 5 + tmpobj[0].parentNode.parentNode.parentNode.offsetLeft + 10;
					//mnushm2ndLevel.style.top = tmpobj[0].parentNode.parentNode.offsetTop + tmpobj[0].parentNode.offsetTop;
					mnushm2ndLevel.style.top = tmpobj[0].offsetTop + tmpobj[0].parentNode.parentNode.offsetTop;
					//tmpobj[0].style.backgroundColor = "#FF0000";
					//tmpobj[0].parentNode.parentNode.style.backgroundColor = "#FF0000";
					tmpobj[0].style.zIndex="102";
					mnushm2ndLevel.style.zIndex="1";
					mnushm2ndLevel.style.display="block";
				}
			}
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
			tmpobj = this.getElementsByTagName('ul');
			if (tmpobj[0] != undefined) {
				if (this.parentNode.id == "nav") { //When LI tag (in 1st Level) is moused out, hide iframe for 2nd Level
					mnushm = document.getElementById('menushim0');
					mnushm.style.display="none";
				} else if(this.parentNode.parentNode.parentNode.id == "nav") { //When LI tag (in 2nd Level) is moused out, hide iframe for 3nd Level
					mnushm2ndLevel = document.getElementById('menushim1');
					mnushm2ndLevel.style.display="none";
				}
			}
		}
		// verifico si posee una accion definida
		var arefs = sfEls[i].getElementsByTagName("A");
		if (arefs != null) {
			if (arefs[0].href != 'javascript:;') {
				sfEls[i].onclick=function() {
					if (document.getElementById('nav') == null) return;
					var items = document.getElementById("nav").getElementsByTagName("LI");
					for (var ww=0; ww<items.length; ww++) {
						items[ww].focus=null;
						items[ww].onmouseover=null;
						items[ww].onmouseout=null;
					}
					if(this.parentNode.parentNode.parentNode.id == "nav") {
						this.parentNode.style.display="none";
					}
					blockPage();
					showLoadingMessage();
					return true;		
				}
			}
		}		
	}
}
/*
mcAccessible Function applies ONFOCUS and ONBLUR states to each A (if its parent LI has subordinate levels) in the UL (id="nav)".
*/
mcAccessible = function() {
	if (document.getElementById('nav') == null) return;
	var mcEls = document.getElementById("nav").getElementsByTagName("A");
	for (var i=0; i<mcEls.length; i++) {
		// ONFOCUS Actions applied to A Tags if Subordinate Menus exist
		mcEls[i].onfocus=function() {
			keyboardFocus = this;
			this.className+=(this.className.length>0? " ": "") + "sffocus"; //a:focus
			this.parentNode.className+=(this.parentNode.className.length>0? " ": "") + "sfhover"; //li < a:focus
			if(this.parentNode.parentNode.parentNode.nodeName == "LI") {
				this.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < a:focus
				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < ul < li < a:focus
				}
			}
			// IFRAME fix
			tmpobj = this.parentNode.getElementsByTagName('ul');
			if(tmpobj[0] != undefined){
				tmpobj2 = tmpobj[0].getElementsByTagName('li');
				if(this.parentNode.parentNode.id == "nav"){  //When A tag (in 1st Level) is in Focus Place iframe behind exposed 2nd Level
					mnushm = document.getElementById('menushim0');
					mnushm.style.left = tmpobj[0].offsetLeft;
					mnushm.style.top = tmpobj[0].offsetTop;
					mnushm.style.width = tmpobj2[0].offsetWidth;
					mnushm.style.height = tmpobj[0].offsetHeight;
					tmpobj[0].style.zIndex="101";
					mnushm.style.zIndex="0";
					mnushm.style.display="block";
					mnushm2ndLevel = document.getElementById('menushim1');
					mnushm2ndLevel.style.display="none";
				} else if(this.parentNode.parentNode.parentNode.parentNode.id == "nav") {  //When A tag (in 2nd Level) is in Focus Place iframe behind exposed 3rd Level
					tmpobj3 = tmpobj[0].parentNode.parentNode;
					tmpobj4 = tmpobj3.getElementsByTagName('li');
					mnushm = document.getElementById('menushim0');
					mnushm2ndLevel = document.getElementById('menushim1');
					mnushm.style.left = tmpobj3.offsetLeft;
					mnushm.style.top = tmpobj3.offsetTop;
					mnushm.style.width = tmpobj4[0].offsetWidth;
					mnushm.style.height = tmpobj3.offsetHeight;
					mnushm.style.zIndex="0";
					mnushm.style.display="block";
					mnushm2ndLevel.style.width = tmpobj2[0].offsetWidth;
					mnushm2ndLevel.style.height = tmpobj[0].offsetHeight;
					mnushm2ndLevel.style.left = tmpobj[0].offsetLeft + tmpobj[0].parentNode.parentNode.parentNode.offsetLeft + 10;
					mnushm2ndLevel.style.top = tmpobj[0].parentNode.parentNode.offsetTop + tmpobj[0].parentNode.offsetTop;
					tmpobj[0].style.zIndex="102";
					mnushm2ndLevel.style.zIndex="1";
					mnushm2ndLevel.style.display="block";
				} 
			} else {
				if (this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id == "nav") {
					tmpobj = this.parentNode.parentNode;
					tmpobj2 = tmpobj.getElementsByTagName('li');
					tmpobj3 = tmpobj.parentNode.parentNode;
					tmpobj4 = tmpobj3.getElementsByTagName('li');
					mnushm = document.getElementById('menushim0');
					mnushm2ndLevel = document.getElementById('menushim1');
					mnushm.style.left = tmpobj3.offsetLeft;
					mnushm.style.top = tmpobj3.offsetTop;
					mnushm.style.width = tmpobj4[0].offsetWidth;
					mnushm.style.height = tmpobj3.offsetHeight;
					mnushm2ndLevel.style.width = tmpobj2[0].offsetWidth;
					mnushm2ndLevel.style.height = tmpobj.offsetHeight;
					mnushm2ndLevel.style.left = tmpobj.offsetLeft + tmpobj.parentNode.parentNode.parentNode.offsetLeft + 10;
					mnushm2ndLevel.style.top = tmpobj.parentNode.parentNode.offsetTop + tmpobj.parentNode.offsetTop;
					tmpobj3.style.zIndex="101";
					mnushm.style.zIndex="0";
					mnushm.style.display="block";
					tmpobj.style.zIndex="102";
					mnushm2ndLevel.style.zIndex="1";
					mnushm2ndLevel.style.display="block";
				} else if (this.parentNode.parentNode.parentNode.parentNode.id == "nav") {
					tmpobj = this.parentNode.parentNode;
					tmpobj2 = tmpobj.getElementsByTagName('li');
					mnushm = document.getElementById('menushim0');
					mnushm.style.left = tmpobj.offsetLeft;
					mnushm.style.top = tmpobj.offsetTop;
					mnushm.style.width = tmpobj2[0].offsetWidth;
					mnushm.style.height = tmpobj.offsetHeight;
					tmpobj.style.zIndex="101";
					mnushm.style.zIndex="0";
					mnushm.style.display="block";
					mnushm2ndLevel = document.getElementById('menushim1');
					mnushm2ndLevel.style.display="none";
				} else if (this.parentNode.parentNode.id == "nav") {
					mnushm = document.getElementById('menushim0');
					mnushm.style.display="none";
					mnushm2ndLevel = document.getElementById('menushim1');
					mnushm2ndLevel.style.display="none";
				}
			}
		}
		// ONBLUR Actions applied to A Tags if Subordinate Menus exist
		mcEls[i].onblur=function() {
			keyboardFocus = null;
			this.className=this.className.replace(new RegExp("( ?|^)sffocus\\b"), "");
			this.parentNode.className=this.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
			mnushm = document.getElementById('menushim0');
			//mnushm.style.display="none";
			mnushm2ndLevel = document.getElementById('menushim1');
			if(this.parentNode.parentNode.parentNode.nodeName == "LI") {
				this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
				mnushm.style.display="none";
				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
					mnushm2ndLevel.style.display="none";
				}
			}
			
		}
		mcEls[i].onmouseup=function() {
			this.blur();
		}
	}
}

// only ie needs the sfHover script. all need the accessibility script...
if(window.addEventListener) window.addEventListener('load', mcAccessible, false); // gecko, safari, konqueror and standard
else if(document.addEventListener) document.addEventListener('load', mcAccessible, false); // opera 7
else if(window.attachEvent) { // win/ie
	window.attachEvent('onload', sfHover);
	window.attachEvent('onload', mcAccessible);
	window.attachEvent('onload', makeFrame);
	
} else { // mac/ie5
	if(typeof window.onload == 'function') {
		var existing = onload;
		window.onload = function() {
			existing();
			sfHover();
			mcAccessible();
		}
	} else {
		window.onload = function() {
			sfHover();
			mcAccessible();
		}
	}
}